package Week.w145;

/**
 * @program Leetcode
 * @description:
 * @author: lishangsheng
 * @create: 2019/07/16 10:26
 */
public class problem03 {
    public int longestWPI(int[] hours) {
        int length=hours.length;
        int[] array=new int[length];
        for (int i=0;i<length;i++){
            if(hours[i] > 8){
                array[i]=1;
            }else {
                array[i]=-1;
            }
        }
        int maxLength = 0;
        for (int i = 0; i < hours.length; i++) {
            int result = 0;
            for (int j = i; j < hours.length; j++) {

                result += array[j];
                if (result > 0 && j - i + 1 > maxLength) {
                    maxLength = j - i + 1;
                }
            }
        }
        return maxLength;
    }
}
